package com.example.demo.service.impl;

import com.example.demo.dao.AreaRepository;
import com.example.demo.model.entity.AreaModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class AreaService {

    @Autowired
    AreaRepository areaRepository;

    public void save(AreaModel area) {
        areaRepository.save(area);
    }

    public AreaModel findByAreaCode(String areaCode) {
        List<AreaModel> areaList = areaRepository.findByAreaCode(areaCode);
        return CollectionUtils.isEmpty(areaList) ? null : areaList.get(0);
    }

}
